package com.example.mvp.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;

import java.lang.ref.WeakReference;

public class BasePresenter<V> implements RxPresenter<V>{

    public WeakReference<V>mWeakReference=null;
    public V mView;
    @Override
    public void bindView(V v) {
        mWeakReference = new WeakReference<>(v);
        if (mWeakReference!=null){
            mView=mWeakReference.get();
        }

    }

    public V getmView() {
        return mView;
    }

    @Override
    public void destoryView() {
        if (mWeakReference!=null){
            mWeakReference.clear();
            mWeakReference=null;
        }
        if (mView!=null){
            mView=null;
        }


    }
    @Override
    public LifecycleProvider getLifecycleProvider() {
        if (getmView()!=null){
            return (LifecycleProvider) mView;
        }
        return null;
    }
}
